class_name CharacterAnmCtrl
extends AnimationTree

# 动画播放器组件
@onready var animation_player: AnimationPlayer = $".."

#动画状态机
@onready var state_machine: AnimationNodeStateMachinePlayback = self.get("parameters/playback")


#region 生命周期

func _ready() -> void:
	if state_machine != null:
		# print(typeof(state_machine))
		# print(state_machine.get_class())
		pass
	if animation_player != null:
		# print("animation_player 引用初始化完毕,", animation_player)
		pass
	else:
		print("CharacterAnmCtrl 中 animation_player 初始化失败")

#endregion

#根据动画名称播放动画
func play_by_anmation_name(name: String) -> void:
	state_machine.travel(name)

#根据动画名称设置一维参数值
func update_anm_one_param(name: String, value: float) -> void:
	set("parameters/" + name + "/blend_position", value)

#获取当前动画的播放比率
func get_cur_anm_play_rate() -> float:
	return state_machine.get_current_play_position()
